#include "Path.h"

namespace zg_util{
    string Path::GetCurExeAbsolutePath(){
        char current_absolute_path[MAX_SIZE]={0};
        //获取当前程序绝对路径
        int cnt = readlink("/proc/self/exe", current_absolute_path, MAX_SIZE);
        if (cnt < 0 || cnt >=MAX_SIZE)
        {
            return string();
        }
        //获取当前目录绝对路径，即去掉程序名
        int i;
        for (i = cnt; i >=0; --i)
        {
            if (current_absolute_path[i] == '/')
            {
                current_absolute_path[i+1] = '\0';
                break;
            }
        }
        return string(current_absolute_path);
    }

    string Path::GetCurExeAbsoluteFilePath() {
        char current_absolute_path[MAX_SIZE]={0};
        //获取当前程序绝对路径
        int cnt = readlink("/proc/self/exe", current_absolute_path, MAX_SIZE);
        if (cnt < 0 || cnt >=MAX_SIZE)
        {
            return string();
        }
        return string(current_absolute_path);
    }
}